<!-- 登录视图：认证与跳转 -->
<template>
  <div>
    <h2>{{ $t('login') }}</h2>
    <form @submit.prevent="onSubmit">
      <input v-model="username" v-focus placeholder="用户名" />
      <input v-model="password" type="password" placeholder="密码" />
      <button type="submit">登录</button>
    </form>
  </div>
  
</template>

<script>
export default {
  name: 'LoginPage',
  data() { return { username: '', password: '' } },
  methods: {
    async onSubmit() {
      try {
        await this.$store.dispatch('auth/login', { username: this.username, password: this.password })
        const redirect = this.$route.query.redirect || '/dashboard'
        this.$router.replace(redirect)
      } catch (e) { /* ignore error handled by global module */ }
    }
  }
}
</script>

